const DB = require('../../../utils/db')
const JwtUtil = require('../../../utils/jwt')
/**
 * GET,
 * 处理群成员申请
 */

module.exports = async (ctx) => {
  // 获取token
 
  let groupid = ctx.request.query.groupid
  let userid = ctx.request.query.userid
  let applyStatus = ctx.request.query.applyStatus
  // 同意or拒绝
  const res = await DB.query(
    `update user_group_apply set applyStatus=${parseInt(
      applyStatus
    )} where userid='${userid}' and groupid='${groupid}'`
  )
  // 同意-在user_group表中加入这个人和群
  if (parseInt(ctx.request.query.applyStatus) === 3) {
    const res1 = await DB.query(
      `insert into user_group(groupid, userid, createTime) values('${groupid}','${userid}',now())`
    )
    ctx.body = {
      code: 0,
      data: 'ok',
    }
    return
  }
  // 拒绝，不操作
  ctx.body = {
    code: 0,
    data: res,
  }
}
